﻿#include "addstudentdlg.h"
#include "addstudentdlg_p.h"
#include "ui_addstudentdlg.h"

#include <qdebug.h>

AddstudentdlgPrivate::AddstudentdlgPrivate(Addstudentdlg *parent) :
    task(DataEngine::Task::instance()),
    q(parent)
{
}

inline void AddstudentdlgPrivate::initializeMember()
{
    qDebug( "in %s\n",__func__);
    //q->ui->lineEdit->setVisible(false);                             //不可见的lineEdit，用于绑定field
    //q->registerField("gradeNum", q->ui->lineEdit);                  //注册gradeNum域
    updateInfo( -1 );
}

inline void AddstudentdlgPrivate::connectSignalsAndSlots()
{
    //connect(q->ui->gradeTreeWidget,     SIGNAL(itemClicked(QTreeWidgetItem*,int)),
    //        this,                       SLOT(doItemClicked(QTreeWidgetItem*,int)));
    //connect( q->ui->pushButton_next,      SIGNAL( clicked()) ,
    //         this,                        SLOT(  addStudentAllInfo()) );
    //connect( q->ui->pushButton_ok,        SIGNAL( clicked() ),
    //         this,                        SLOT(  addStudentAllInfo()) );
    //connect( q->ui->comboBox_grade,       SIGNAL(currentIndexChanged(int)),
    //         this,                        SLOT(updateInfo( int )));
    connect( q->ui->comboBox_grade,         SIGNAL(currentIndexChanged(int)),
             this,                          SLOT(updateInfo(int)) );
    connect( q->ui->pushButton_next,        SIGNAL(clicked()),
             this,                          SLOT( addStudentAllInfo()));

}

inline void AddstudentdlgPrivate::completeConstruct()
{
    //QPointer<QTreeWidget> gradeTreePtr = q->ui->gradeTreeWidget;    //年级列表控件指针

    //(void)task->lookup<DataEngine::FillGradeListTask>()->run(gradeTreePtr, tr("当前所有年级"));
}

inline bool AddstudentdlgPrivate::validatePage()
{
    //QList<QTreeWidgetItem *> selectedSet = q->ui->gradeTreeWidget->selectedItems();

    //return !selectedSet.isEmpty();
}


void AddstudentdlgPrivate::test( )
{
}

 void AddstudentdlgPrivate::updateInfo( int index )
{
    qDebug( "in %s,index:%d\n",__func__,index );
    //return;
    QPointer<QComboBox> combaBoxGreade = q->ui->comboBox_grade;
    QPointer<QComboBox> combaBoxClass = q->ui->comboBox_class;
    (void)task->lookup<DataEngine::AddStudentGetGladeTask>()->run(combaBoxGreade,combaBoxClass,index);

 }

void AddstudentdlgPrivate::addStudentAllInfo( )
{
     qDebug( "in %s\n",__func__ );
     QPointer<Addstudentdlg> addstudent = q;
     (void)task->lookup<DataEngine::AddStudentTask>()->run(addstudent);
}


Addstudentdlg::Addstudentdlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Addstudentdlg),
    d(new AddstudentdlgPrivate(this))
{
    ui->setupUi(this);
    d->initializeMember();
    d->connectSignalsAndSlots();
}

Addstudentdlg::~Addstudentdlg()
{
    delete ui;
    delete d;
}

void Addstudentdlg::initializePage()
{
    //d->completeConstruct();
}

bool Addstudentdlg::isComplete() const
{
    //return d->validatePage();
}

bool Addstudentdlg::validatePage()
{
    //rern d->validatePage();
}

void Addstudentdlg::on_pushButton_ok_clicked()
{
    //on_pushButton_next_clicked( );
}

void Addstudentdlg::on_comboBox_grade_currentIndexChanged(const QString &arg1)
{

}

void Addstudentdlg::on_pushButton_next_clicked()
{

}
